package com.hai.udp;

import org.apache.mina.core.service.IoHandler;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.FilterEvent;

import java.util.logging.Logger;


public class MyHandler implements IoHandler {
    String tag = "myhandler";

    public MyHandler() {
    }

    public MyHandler(String tag) {
        this.tag = tag + ",";
    }

    private Logger logger = Logger.getLogger(this.getClass().getSimpleName());

    @Override
    public void sessionCreated(IoSession session) throws Exception {
        logger.info(tag + "sessionCreated() called with: session = [" + session + "]");
    }

    @Override
    public void sessionOpened(IoSession session) throws Exception {
        logger.info(tag + "sessionOpened() called with: session = [" + session + "]");
    }

    @Override
    public void sessionClosed(IoSession session) throws Exception {
        logger.info(tag + "sessionClosed() called with: session = [" + session + "]");
    }

    @Override
    public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
        logger.info(tag + "sessionIdle() called with: session = [" + session + "], status = [" + status + "]");
    }

    @Override
    public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
        logger.info(tag + "exceptionCaught() called with: session = [" + session + "], cause = [" + cause + "]");
    }

    @Override
    public void messageReceived(IoSession session, Object message) throws Exception {
        logger.info(tag + "messageReceived() called with: session = [" + session + "], message = [" + message + "]");
    }

    @Override
    public void messageSent(IoSession session, Object message) throws Exception {
        logger.info(tag + "messageSent() called with: session = [" + session + "], message = [" + message + "]");
    }

    @Override
    public void inputClosed(IoSession session) throws Exception {
        logger.info(tag + "inputClosed() called with: session = [" + session + "]");
    }

    @Override
    public void event(IoSession session, FilterEvent event) throws Exception {
        logger.info(tag + "event() called with: session = [" + session + "], event = [" + event + "]");
    }
}